{% from "macros/forms.html" import form_input, form_textarea, form_fileinput, form_select %}
{% from "macros/worker.html" import worker_status %}
{% set osint_id = osint_source.id | default("0", true) %}
{% set form_error = form_error | default({}) %}

<div class="bg-base-100 p-4">
  <div class="join gap-4 mb-5 w-3/4 ml-[10%]">
    <h1 class="text-3xl font-bold">{{ submit_text }}</h1>
    {% include "osint_source/state_button.html" %}
  </div>

  <p class="text-base-content/60 text-[0.7rem] mb-5 w-1/2 ml-[10%]">ID: {{ osint_id }}</p>
  {% if osint_source.status %}
    <div class="mb-5 w-1/2 ml-[10%]">{{ worker_status(osint_source.status) }}</div>
  {% endif %}

  <form id="{{ model_name }}-form"
        class="w-1/2 ml-[10%]"
        {{ form_action }}
        hx-swap="innerHTML"
        hx-target="#form-container"
        hx-target-error="#form-container">
    {% include "partials/admin_form_error.html" %}
    {{ form_input('Name', 'name', osint_source.name, form_error.name) }}
    {{ form_textarea('Description', 'description', osint_source.description, form_error.description, required=False) }}
    {{ form_fileinput('Icon', 'icon', osint_source.icon, type='file', required=False) }}

    <label class="select w-full mb-5">
      <span class="label">Collector Type</span>
      <select id="collector_type"
              name="type"
              required
              class="validator select w-full"
              hx-get="{{ url_for('admin.osint_source_parameters', osint_source_id=osint_id) }}"
              hx-trigger="change"
              hx-include="#collector_type"
              hx-target="#parameters"
              hx-swap="innerHTML"
              {% if osint_source.type %}disabled{% endif %}>
        {% if not osint_source.collector_type %}<option value="" selected disabled>Select a collector type</option>{% endif %}
        {% for option in collector_types -%}
          <option value="{{ option.id }}" {% if option.id==osint_source.type %}selected{% endif %}>{{ option.name }}</option>
        {% endfor -%}
      </select>
      {% if osint_source.type %}<input type="hidden" name="type" value="{{ osint_source.type }}">{% endif %}
    </label>
    <div id="parameters">{% include "partials/worker_parameters.html" %}</div>

    <input type="submit" class="btn btn-primary w-full" value="{{ submit_text }}" />
  </form>
</div>
